<?php

namespace App\Service\AppStore;

use App\Helpers\AliyunUtil;
use App\Model\AppStore\Article;
use App\Service\BaseService;

/**
 * 分类文章列表
 */
class ArticleListService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        //分类ID
        $cateId = $this->request->input('catagory_id', 1);
        //页码
        $page = $this->request->input('page', 1);
        $data = Article::getList($cateId, $page);
        $ret['list'] = [];
        array_walk($data, function ($item) use (&$ret) {
            $ret['list'][] = [
                'article_id' => $item['id'],
                'jump_type' => 'h5',
                'title' => $item['title'],
                'thumb' => AliyunUtil::imageResize(AliyunUtil::IMG_HOST_V2 . $item['thumb'], 400, 250),
                'sub_text' => $item['sub_text'],
                // 'content' => $item['content'],
                'link' => $item['link'] ?: '',
            ];
        });
        return $ret;
    }
}
